<template>
    <CommonContainer title="车辆信息">
        <el-descriptions v-if="customerInfo">
            <el-descriptions-item label="车牌号" v-if="customerInfo.outStorageVo">{{customerInfo.outStorageVo.carNo|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="车架号" v-if="customerInfo.outStorageVo">{{customerInfo.outStorageVo.vinNo|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="发动机号码" v-if="customerInfo.outStorageVo">{{customerInfo.outStorageVo.engineNo|filterNull}}</el-descriptions-item>

            <el-descriptions-item label="排量" v-if="customerInfo.outStorageVo">{{customerInfo.outStorageVo.liter|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="环保标准" v-if="customerInfo.outStorageVo">{{customerInfo.outStorageVo.environmentalStandards|filterNull}}</el-descriptions-item>

            <el-descriptions-item label="是否包含替车" v-if="customerInfo.outStorageVo">{{customerInfo.orderInfoVo.isReplacementCar==0?'否':'是'|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="替车时效" v-if="customerInfo.outStorageVo">{{customerInfo.orderInfoVo.replacementCarValidity|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="合同时效" v-if="customerInfo.outStorageVo">{{customerInfo.orderInfoVo.contractValidity|filterNull}}</el-descriptions-item>

            <el-descriptions-item label="采购单价" v-if="customerInfo.outStorageVo">{{customerInfo.outStorageVo.purchasePrice|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="指导价" v-if="customerInfo.outStorageVo">{{customerInfo.outStorageVo.guidancePrice|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="每期租金" v-if="customerInfo.orderInfoVo">{{customerInfo.orderInfoVo.planRent|filterNull}}</el-descriptions-item>
            
            <el-descriptions-item label="租赁期（月）" v-if="customerInfo.orderInfoVo">{{customerInfo.orderInfoVo.leaseTerm|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="入库里程(km)" v-if="customerInfo.outStorageVo">{{customerInfo.outStorageVo.inboundMileage|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="入库油量(%)" v-if="customerInfo.outStorageVo">{{customerInfo.outStorageVo.inboundOilQuantity|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="是否安装GPS" v-if="customerInfo.outStorageVo">
              <span v-if="customerInfo.gpsDetailVo.isInstallation==1">否</span>
              <span v-else-if="customerInfo.gpsDetailVo.isInstallation==0">是</span>
              <span v-else>--</span>
            </el-descriptions-item>

            <el-descriptions-item label="GPS设备状态" v-if="customerInfo.outStorageVo">{{customerInfo.gpsDetailVo.gpsState|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="GPS品牌" v-if="customerInfo.outStorageVo">{{customerInfo.gpsDetailVo.gpsBrand|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="GPS设备类型" v-if="customerInfo.outStorageVo">{{customerInfo.gpsDetailVo.gpsType|filterNull}}</el-descriptions-item>

            <el-descriptions-item label="GPS时效" v-if="customerInfo.outStorageVo">{{customerInfo.gpsDetailVo.gpsValidity|filterNull}}</el-descriptions-item>
            <el-descriptions-item label="订单编码" v-if="customerInfo.outStorageVo" ><span class="goorder" @click="goOrder(customerInfo.orderInfoVo.orderNo)">{{customerInfo.orderInfoVo.orderNo|filterNull}}</span></el-descriptions-item>
            <el-descriptions-item label="合同编码" v-if="customerInfo.outStorageVo" ><span class="goorder" @click="goOrder(customerInfo.orderInfoVo.orderNo)">{{customerInfo.orderInfoVo.contractNo|filterNull}}</span></el-descriptions-item>
            <el-descriptions-item label="入库编码" v-if="customerInfo.outStorageVo" ><span class="goorder" @click="goWarehousing(customerInfo.carOutStorage.inboundId,customerInfo.outStorageVo.purchaseSource)">{{customerInfo.outStorageVo.inboundCode|filterNull}}</span></el-descriptions-item>
        </el-descriptions>
    </CommonContainer>
</template>

<script>
import {
  getPurchaseQualifiedCard, carGpsInstall, getQuotaProductByOrderCar, carGpsMonitoring, carPrchaseTax, carInspection, carInsurance, carInspectionNextTime
} from "@/api/carInventory/inInventory";
import { OrderParam,} from '@/api/finance/manage/collect/api.js';
import moment from "moment";
export default {
    components: {},
    props: {
        value: {
        type: Object,
        },
    },
    data() {
        return {
            ossId: '1759761984477720577',
        }
    },
    computed:{
        customerInfo: {
            get() {
                return this.value;
                return this.useVModel.call(this);
            },
            set(val) {
                this.$emit("input", val);
            }, 
        },
    },
    methods: {
      goOrder(orderCode){
          if (this.Empty(orderCode)) return;
          return new Promise(resolve => {
              OrderParam(orderCode)
              .then(res => {
                  if (res.code == 200) {
                      this.$router.push({
                          name: 'OrderDetails',
                          query: {
                          type: res.data.carType,
                          beFrom: 'OrderView',
                          orderId: res.data.orderId,
                          preOrderId: res.data.preOrderId,
                          calcSchemeId: res.data.calcSchemeId,
                          isMenu: this.$route.query.isMenu,
                          },
                      })
                  } else {
                  throw new Error(res);
                  }
              })
          .catch(err => resolve());
        });
      },
      goWarehousing(id,purchaseSource){
        if (this.Empty(id)) return;
        this.$router.push({
            name: 'InInventoryDetail',
            query: {
                inboundId: id,
                viewType: 0,
                source: purchaseSource == '4' ? 1 : 2,// 用来判断显示采购信息还是外部转租赁
            }
        })
      },
      getCarGpsInfo(carId){
        if (this.Empty(carId)) return;
        carGpsInstall(carId).then(res => {
          var d = res.data;
          if (!d) {
            d = {};
          }
          console.log(d,'111111111')
          this.customerInfo.gpsDetailVo.gpsType = {'1':'有线','2':'无线','3':'有线+无线'}[new String(d.equipmentType).trim()];
          var year = d.gpsServicePeriod?.match(/\d*/)[0]
          this.customerInfo.gpsDetailVo.installTime = d.installTime;
          this.customerInfo.gpsDetailVo.gpsBrand = d.gpsBrand;
          this.customerInfo.gpsDetailVo.gpsValidity =d.installTime? moment(d.installTime).add(year^0, 'years').format("YYYY-MM-DD HH:mm:ss"):'--';
        }).finally(() => {
          this.loading = false
        })
      },
    
      getCarGpsMonitoring(carId){
        if (this.Empty(carId)) return;
        carGpsMonitoring(carId).then(res => {
          var d = res.data;
          if (!d) {
            d = {};
          }
          this.customerInfo.gpsDetailVo.gpsState = d.gpsState;
        }).finally(() => {
          this.loading = false
        })
      },
      detailInfo(){
        console.log(this.customerInfo,'this.customerInfo')
        console.log('进来了')
        var _this = this;
        if (this.customerInfo != null && this.customerInfo.carOutStorage != null) {
         // 用的是入库id
         console.log(this.customerInfo.inboundId,'this.customerInfo.inboundIdthis.customerInfo.inboundId')
         const param = {
          inboundId:this.customerInfo.inboundId?this.customerInfo.inboundId:-1,
          carId:this.customerInfo.carOutStorage.carId?this.customerInfo.carOutStorage.carId:-1,
         }
          this.getCarGpsInfo(param);
          this.getCarGpsMonitoring(this.customerInfo.carOutStorage.carId);
         
        } else {
        //   setTimeout(function () {
        //     _this.detailInfo();
        //   }, 100)
        }
      },
    },
  created() {

    this.detailInfo()
  },

}
</script>

<style lang="scss" scoped>
.goorder{
    color:blue;
    cursor: pointer;
}
</style>
